// import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import filter from './filter'
import app from './utils/app'
// import appMock from './mock/app'//用于测试app方法,测试完可以注释此行
import 'babel-polyfill'
import 'normalize.css'
import _ from 'lodash'
import '@/assets/css/global.less'
import FastClick from 'fastclick'
import VueLazyLoad from 'vue-lazyload'
import '@/assets/fonts/yansIcon.less'
import dot from '@/utils/dot'
// import '@/utils/onePass-1.0-js.js'

/* eslint-disable */
Vue.prototype._dot = dot
dot.init ( process.env.VUE_APP_DOT_URL )

//处理支付宝小程序类型
new Promise ( ( resolve , reject ) => {
  let ua = navigator.userAgent.toLowerCase ()
  //console.log(navigator.userAgent)
  if ( ua.match ( /AlipayClient/i ) == 'alipayclient' ) {
    window.my.getEnv ( ( content ) => {
      console.log ( 'content.miniprogram' + content.miniprogram ) // true
      store.dispatch ( 'setAliminiFlag' , content.miniprogram )
      resolve ()
    } )
  } else {
    resolve ()
  }
} ).then ( function () {
  
  Vue.prototype._ = _
  
  FastClick.attach ( document.body )
  Vue.config.productionTip = false
  
  //vue懒加载插件，这里只做通用逻辑，如需使用请查阅插件官方文档自行更改
  Vue.use ( VueLazyLoad , {
    preLoad : 1.3 ,
    error : '@/assets/imgs/error.png' ,//加载错误图片地址
    loading : '@/assets/imgs/loading.png' ,//加载中图片地址
    attempt : 5//加载错误后最大尝试次数
  } )
  
  // //vconsole插件
  if ( process.env.VUE_APP_USE_VCONSOLE == 'true' ) {
    /* eslint-disable no-unused-vars */
    var VConsole = require('vconsole');
    var vconsole = new VConsole();
  }
  // 初始化浏览器类型，设置系统、平台类型参数
  store.dispatch ( 'initSystemType' )
  
  // 执行全局初始化（APP等）
  Vue.prototype.$app = app
  app.init ()
  // 全局过滤处理
  filter.doFilters ()
  
  // 是否使用MOCK接口
  if ( 'true' === process.env.VUE_APP_USE_MOCK ) {
    let Mock = require ( './mock' ).default
    console.log ( 'mock' + process.env.VUE_APP_USE_MOCK )
    Mock.bootstrap ()
  }
  //解决ios移动端input调软键盘问题
  FastClick.prototype.focus = function ( targetElement ) {
    let length;
    let isIphone = navigator.userAgent.indexOf ( "iPhone" ) != -1;
    if (
      isIphone &&
      targetElement.setSelectionRange &&
      targetElement.type.indexOf ( "date" ) !== 0 &&
      targetElement.type !== "time" &&
      targetElement.type !== "month" &&
      targetElement.type !== "email"
    ) {
      length = targetElement.value.length;
      targetElement.setSelectionRange ( length , length );
      /*修复bug ios 11.3不弹出键盘，这里加上聚焦代码，让其强制聚焦弹出键盘*/
      targetElement.focus ();
    } else {
      targetElement.focus ();
    }
  }
  // appMock.doAppMock()//用于测试app方法,测试完可以注释此行
  new Vue ( {
    router ,
    store ,
    render : h => h ( App )
  } ).$mount ( '#app' )
} )
